package com.rerun.common.quartz;

import org.quartz.spi.TriggerFiredBundle;
import org.springframework.beans.factory.config.AutowireCapableBeanFactory;
import org.springframework.scheduling.quartz.AdaptableJobFactory;

import javax.annotation.Resource;

/**
 * 代理任务工厂.
 * Author: Dax
 * Description:
 * Date: 2017/10/23
 * Time: 23:44
 */

public class DelegateJobFactory extends AdaptableJobFactory {
    @Resource
    private AutowireCapableBeanFactory capableBeanFactory;

    @Override
    protected Object createJobInstance(TriggerFiredBundle bundle) throws Exception {
        Object jobInstance = super.createJobInstance(bundle);
//         通过bean工厂自动注入
        capableBeanFactory.autowireBean(jobInstance);
        return jobInstance;
    }
}
